package servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author：毕龙
 * Date: 2023/7/27 11:15
 */
@WebServlet("/forward")
public class RequestForward extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("请求进来");

        //给request作用域中存放数据
        request.setAttribute("food", "迷药");

        //请求转化法路径
        //RequestDispatcher rd = request.getRequestDispatcher("/hello");
        //rd.forward(request,response);
        RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
        rd.forward(request,response);


    }
}
